package Collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * JDK5之后推出的另一个特性:增强for循环
 *
 */
public class NewForDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        //增强for循环,新循环会依次将每个元素赋值给变量然后进入循环体
        for (String e:c){
            System.out.println(e);
        }
        //新循环遍历数组
        /*
            新循环遍历数组会被改为普通for循环遍历
         */
        String[] array = {"one","two","three","four","five"};
        for (String e:array){
            System.out.println(e);
        }
    }
}
